﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace CommunitySystem.PageView
{
    public partial class OrgForHRWindow : ChildWindow
    {
        private EmpbasicService.EmpBasicServiceClient Client = new EmpbasicService.EmpBasicServiceClient();
        private EmpbasicService.OrgForHRModel model = new EmpbasicService.OrgForHRModel();
        public int ID;
        public bool IsNew = false;
        public OrgForHRWindow(int iD, bool isnew)
        {
            InitializeComponent();
            ID = iD;
            IsNew = isnew;
            if (IsNew)
            {
                this.Title = "新增部门信息";
                model = new EmpbasicService.OrgForHRModel();
                this.DataContext = model;
            }
            else
            {
                this.Title = "编辑部门信息";
                Client.GetOrgForHRModelCompleted += new EventHandler<EmpbasicService.GetOrgForHRModelCompletedEventArgs>(Client_GetOrgForHRModelCompleted);
                Client.GetOrgForHRModelAsync(ID);
            }
        }

        void Client_GetOrgForHRModelCompleted(object sender, EmpbasicService.GetOrgForHRModelCompletedEventArgs e)
        {
            if (e.Result != null)
                model = e.Result[0];
            this.DataContext = model;
        }
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (IsNew == true)
            {
                Client.AddOrgForHRModelCompleted += new EventHandler<EmpbasicService.AddOrgForHRModelCompletedEventArgs>(Client_AddOrgForHRModelCompleted);
                Client.AddOrgForHRModelAsync(model);
            }
            else
            {
                Client.UpdateOrgForHRModelCompleted += new EventHandler<EmpbasicService.UpdateOrgForHRModelCompletedEventArgs>(Client_UpdateOrgForHRModelCompleted);
                Client.UpdateOrgForHRModelAsync(model);
            }
        }

        void Client_UpdateOrgForHRModelCompleted(object sender, EmpbasicService.UpdateOrgForHRModelCompletedEventArgs e)
        {
            if (e.Result == true)
            {
                SilverlightMessageBoxLibrary.Message.InfoMessage("编辑成功！");
                this.DialogResult = true;
            }
        }

        void Client_AddOrgForHRModelCompleted(object sender, EmpbasicService.AddOrgForHRModelCompletedEventArgs e)
        {
            if (e.Result == true)
            {
                SilverlightMessageBoxLibrary.Message.InfoMessage("新增成功！");
                this.DialogResult = true;
            }
        }
        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}
